var rankName = {
	'1':'签约',
	'2':'应诊',
	'3':'预约',
	'4':'好评',
	'5':'投诉'
}
var dataType = localStorage.getItem('dataType');
hui("#goCommunitycity span").html(rankName[dataType])
console.log('dataType:'+dataType);
var dataUrlInfo = {
	'provinceWeek':'/hdds/statistics/province/signList/lastweek/'+userInfos.provinceId,//排行榜（省）》上一周
	'provinceMonth':'/hdds/statistics/province/signList/lastmonth/'+userInfos.provinceId,//排行榜（省）》上一月
	'provinceSeason':'/hdds/statistics/province/signList/lastseason/'+userInfos.provinceId,//排行榜（省）》上一季
	'cityWeek':'/hdds/statistics/city/signList/lastweek/'+userInfos.cityId,//排行榜（市）》上一周
	'cityMonth':'/hdds/statistics/city/signList/lastmonth/'+userInfos.cityId,//排行榜（市）》上一月
	'citySeason':'/hdds/statistics/city/signList/lastseason/'+userInfos.cityId,//排行榜（市）》上一季
	'areaWeek':'/hdds/statistics/area/signList/lastweek/'+userInfos.areaId,//排行榜（县）》上一周
	'areaMonth':'/hdds/statistics/area/signList/lastmonth/'+userInfos.areaId,//排行榜（县）》上一月
	'areaSeason':'/hdds/statistics/area/signList/lastseason/'+userInfos.areaId//排行榜（县）》上一季
	
}
function getsignuser(dataUrl){
//	alert(1) 
//	if(dataType == 1){
		var pravceArray = [];
		var pravceNum = 0;
		var options = '';
		
		myajax(dataUrl,function(res){
			
			hui("#allsign li").remove();
			if(JSON.stringify(res.body) == '{}'){
	    		hui('.commonLength').html('');
	    		hui("#allsign").html('<p style="width:100%;text-align:center;color:#f00;">暂无排行榜数据</p>');
	    	}
			for(var arr in res.body){ 
	    		console.log(JSON.stringify(arr)+'----'+JSON.stringify(res.body[arr]));
	    		pravceNum = 0;
	    		for(var i= 0; i < res.body[arr].length; i++){
	    			if(dataType == 1){	    				
	    				pravceNum +=res.body[arr][i].signNum;
	    			}else if(dataType == 2){
	    				pravceNum +=res.body[arr][i].consultationNum;
	    			}else if(dataType == 3){
	    				pravceNum +=res.body[arr][i].consultationNum;
	    			}else if(dataType == 4){
	    				pravceNum +=res.body[arr][i].praiseNum;
	    			}else if(dataType == 5){
	    				pravceNum +=res.body[arr][i].complaintNum;
	    			}
	    		}
	    		pravceArray.push({
	    			arr:arr,
	    			num:pravceNum
	    		})
	    	}
			
//			console.log('26'+JSON.stringify(pravceArray));
			//排序
			pravceArray.sort(function(a,b){
				return b.num-a.num;
			})
			
			//渲染列表
			if(pravceArray.length>0){
				hui(".oneRankingarr").html(pravceArray[0].arr);
				hui(".oneRankingnum").html(pravceArray[0].num);
				hui(".twoRankingarr").html("暂无");
				hui(".twoRankingNum").html("0");
				hui(".threeRankingarr").html("暂无");
				hui(".threeRankingnum").html("0");
				if(pravceArray.length>1){
					hui(".twoRankingarr").html(pravceArray[1].arr);
					hui(".twoRankingNum").html(pravceArray[1].num);
				}
				if(pravceArray.length>2){
					hui(".threeRankingarr").html(pravceArray[2].arr);
					hui(".threeRankingnum").html(pravceArray[2].num);
				}
				for (var j = 0; j < pravceArray.length ; j++) {
		    		options +=  '<li>'+
								'<a href="javascript:void(0);">'+
									'<div class="hui-list-icons">'+
										'<span >'+(j+1)+'</span>'+
									'</div>'+
									'<div class="hui-list-text">'+
										'<span >'+pravceArray[j].arr+'</span> '+
										'<div class="hui-list-info">'+
											'<span>'+pravceArray[j].num+'</span><i class="iconfont icon-ai62"></i>'+
										'</div>'+
									'</div>'+
								'</a>'+
							'</li>'
		    	}
		    	hui("#allsign").html(options);
		    } else {
		    	hui(".oneRankingarr").html("暂无");
				hui(".oneRankingnum").html("0");
				hui(".twoRankingarr").html("暂无");
				hui(".twoRankingNum").html("0");
				hui(".threeRankingarr").html("暂无");
				hui(".threeRankingnum").html("0");
		    }
		})
//	}
	
}
function myajax(dataUrl,successfn){
	hui.ajax({
	    type : 'GET',
	    url : globleobj['domain']+dataUrl,
	    data :'',
	    beforeSend : function(){hui.loading();},
	    complete   : function(){hui.closeLoading();},
	    success : function(msg){
	    	console.log('getsignuser:'+msg)
	    	var data = JSON.parse(msg)
	    	if(data.rc != 0){
	    		hui.toast(data.msg);  
	    		return false; 
	    	}
	    	console.log(JSON.stringify(data.body) == '{}')
	    	
	    	successfn(data);
	    },
	    error : function(e){
	        console.log(JSON.stringify(e));
	        hui.iconToast('读取消息失败', 'warn');
	    } 
	}); 
}
//接受
function accesssign(token){
	console.log(token.token)
	hui.ajax({
	    type : 'POST',
	    url : globleobj['domain']+'/doctor/accesssign',
	    data : {'token':token.token,'doc_id':doctorUser.doc_id},
	    beforeSend : function(){hui.loading();},
	    complete   : function(){hui.closeLoading();},
	    success : function(msg){
	    	console.log("accesssign:"+msg) 
	    	var data = JSON.parse(msg);
	    	getsignuser()
	    },
	    error : function(e){
	        console.log(JSON.stringify(e));
	        hui.iconToast('读取消息失败', 'warn');
	    } 
	}); 
}
//function goResident(){
//	hui.open('/html/details/residentDetails.html',{},true);
//}

//点击切换函数可以根据实际业务需求编写业务代码
function changeDom(index){
    index--;
    hui('#cate a').eq(index).addClass('hui-segment-active').siblings().removeClass('hui-segment-active');
    if(userInfos.userLevel == 1 ){
    	if(index == 0){    		
    		getsignuser(dataUrlInfo.provinceWeek);
    	}else if(index == 1){
    		getsignuser(dataUrlInfo.provinceMonth);
    	}else if(index == 2){
    		getsignuser(dataUrlInfo.provinceSeason);
    	}
	}else if(userInfos.userLevel == 2 ){
		if(index == 0){    	
			getsignuser(dataUrlInfo.cityWeek);
    	}else if(index == 1){
    		getsignuser(dataUrlInfo.cityMonth);
    	}else if(index == 2){
    		getsignuser(dataUrlInfo.citySeason);
    	}
	}else if(userInfos.userLevel == 3 ){
		if(index == 0){    	
			getsignuser(dataUrlInfo.areaWeek);
    	}else if(index == 1){
    		getsignuser(dataUrlInfo.areaMonth);
    	}else if(index == 2){
    		getsignuser(dataUrlInfo.areaSeason);
    	}
	}
}
hui.ready(function(){
	if(userInfos.userLevel == 1 ){
		getsignuser(dataUrlInfo.provinceWeek);
	}else if(userInfos.userLevel == 2 ){
		getsignuser(dataUrlInfo.cityWeek);
	}else if(userInfos.userLevel == 3 ){
		getsignuser(dataUrlInfo.areaWeek);
	}
	
	hui('#nav-news').click(function(){
	    hui.open('community.html',{},true);
	});
	
	hui('.goResident').click(function(){
	    hui.open('/html/details/residentDetails.html',{},true);
	});
	
    hui.plusReady(function(){
    	console.log('plusReady');
    });
});